﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using System.Data.Entity;
using C2E2C.Data;
using C2E2C.Repository.Repositories;
using C2E2C.Repository.Repositories.Provider;

namespace C2E2C.Repository
{
    public partial class UnityRepositoryContainer : IRepositoryContainer
    {
        private IUnityContainer unityContainer;
        private LifetimeManager dbContextLifetimeManager;
        public UnityRepositoryContainer(IUnityContainer unityContainer, LifetimeManager dbContextLifetimeManager)
        {
            this.unityContainer = unityContainer;
            this.dbContextLifetimeManager = dbContextLifetimeManager;
            RepositoryRegistration(unityContainer);
        }

        public TRepository Get<TRepository>() where TRepository : class
        {
            try
            {
                return this.unityContainer.Resolve<TRepository>();
            }
            catch (Exception ex)
            {
                throw new NotSupportedException("不支持指定类型的解析", ex);
            }
        }

        partial void RepositoryRegistration(IUnityContainer unityContainer);
    }
}
